<template>
  <div class='progressbar'>
    <progress :percent='percent' activeColor='#ea5a49'></progress>
    <p>{{year}}已经过去了{{days}}天</p>
  </div>
</template>
<script>
export default {
  methods: {
    isLeepYear () {
      if (this.year % 400 === 0) {
        return true
      } else if (this.year % 4 && this.year % 100 !== 0) {
        return true
      } else {
        return false
      }
    },
    getDayOfYear () {
      return this.isLeepYear() ? 366 : 365
    }
  },
  computed: {
    year () {
      return new Date().getFullYear()
    },
    days () {
      let start = new Date()
      start.setMonth(0)
      start.setDate(1)
      let offset = new Date().getTime() - start.getTime()
      return parseInt(offset / 1000 / 60 / 60 / 24) + 1
    },
    percent () {
      return (this.days * 100 / this.getDayOfYear()).toFixed(1)
    }
  }
}
</script>
<style lang="scss">
.progressbar{
  progress{
    margin-bottom: 20rpx;
  }
  p{
    margin: 20rpx 0;
    text-align:center;
  }
}
</style>
